package com.itheima.d7_interface_demo.practice;

import java.util.ArrayList;

public class StudentServiceImpl2 implements StudentService {

    @Override
    public void printAllInfo(ArrayList<Student> students) {
        //记录人数
        int boy = 0;
        int girl = 0;
        System.out.println("--------全班学生信息如下-------");
        for (int i = 0; i < students.size(); i++) {
            Student stu = students.get(i);
            System.out.println("姓名:  = " + stu.getName() + ",性别: " + stu.getSex() + ",成绩: " + stu.getScore());
            //统计人数
            if (stu.getSex() == '男') {
                boy++;
            } else {
                girl++;
            }
        }
        System.out.println("男生人数是: " + boy + ",女生人数是: " + girl);
        System.out.println("班级总人数是: " + (boy + girl));
        System.out.println("------------------------------------");
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double sum = 0;
        double min = students.get(0).getScore();//最低分
        double max = students.get(0).getScore();//最高分

        for (int i = 0; i < students.size(); i++) {
            Student stu = students.get(i);
            sum += stu.getScore();//累加

            //最低分
            if (min > stu.getScore()) {
                min = stu.getScore();
            }
            //最高分
            if (max < stu.getScore()) {
                max = stu.getScore();
            }
        }
        //求平均分
        System.out.println("学生的最高分是: " + max);
        System.out.println("学生的最低分是: " + min);
        System.out.println("平均分: " + (sum - max - min) / (students.size() - 2));
    }
}
